package com.xxlie.shop.domain;

import com.xxlie.auth.config.DbConfig;
import com.xxlie.auth.domain.User;
import com.xxlie.auth.domain.base.BaseEntity;
import org.hibernate.validator.constraints.Length;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

/**
 * 意见反馈
 */
@Entity
@Table(name = DbConfig.DEFAULT_TABLE_PREFIX + "feedback")
public class Feedback extends BaseEntity {
    private Long id;    //自增ID
    private String body;    //反馈内容
    private User user;      //用户信息

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Column(name = "body", length = 300)
    @NotNull(message = "反馈内容不能为空")
    @Length(min = 1, max = 300, message = "反馈内容最多300个字")
    public String getBody() {
        return body;
    }

    public void setBody(String body) {
        this.body = body;
    }

    @ManyToOne(fetch = FetchType.LAZY) //　---> ManyToOne指定了多对一的关系，fetch=FetchType.LAZY属性表示在多的那一方通过延迟加载的方式加载对象(默认不是延迟加载)
    @JoinColumn(name = "uid") //　--->　　通过 JoinColumn 的name属性指定了外键的名称 uid　(注意：如果我们不通过JoinColum来指定外键的名称，系统会给我们声明一个名称)
    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }
}
